1. Technical Field
The disclosed technology relates to the field of memory management systems.
2. Background Art
Even with the dramatic decline in memory costs for small computing devices, there exist many memory-constrained computing devices that do not have the capability of using a storage device to temporally swap-out the content of some portion of memory to free that portion of memory for another use. Consequently, these devices can fail to operate properly if they allocate most or all of their available memory.
A number of techniques have been developed to conserve memory on such memory-constrained computing devices. One of these techniques is termed “copy-on-write”. In general, copy-on-write means that a portion of the device's memory (that contains data, code, etc.) is shared by multiple processes executing in the device. The processes sharing the memory are each mapped to, and have read access to that portion of memory (but do not have write access). Thus, only a single copy of the shared information is in the devices memory and shared by all the sharing processes instead of each of the processes allocating its own copy of the identical information. This works so long as none of the sharing processes need to modify the shared memory. If a process attempts to modify the shared memory, a private copy of the shared information is created by allocating another portion of memory and copying the contents of the shared portion to the newly allocated portion of memory. The newly allocated portion of memory is mapped to the modifying process and the modifying process is given both read and write access to its private copy of the information. The following quotation from a Wikipedia article succinctly summarizes copy-on-write technology:                “The fundamental idea [of copy-on-write] is that if multiple callers ask for resources which are initially indistinguishable, you can give them pointers to the same resource. This fiction can be maintained until a caller tries to modify its “copy” of the resource, at which point a true private copy is created to prevent the changes becoming visible to everyone else. All of this happens transparently to the callers. The primary advantage is that if a caller never makes any modifications, no private copy need ever be created.        Copy-on-write finds its main use in virtual memory operating systems; when a process creates a copy of itself, the pages in memory that might be modified by either the process or its copy are marked copy-on-write. When one process modifies the memory, the operating system's kernel intercepts the operation and copies the memory so that changes in one process's memory are not visible to the other.        Another use is in the calloc function. This can be implemented by having a page of physical memory filled with zeroes. When the memory is allocated, the pages returned all refer to the page of zeroes and are all marked as copy-on-write. This way, the amount of physical memory allocated for the process does not increase until data is written. This is typically only done for larger allocations.        Copy-on-write can be implemented by telling the MMU that certain pages in the process's address space are read-only. When data is written to these pages, the MMU raises an exception which is handled by the kernel, which allocates new space in physical memory and makes the page being written to correspond to that new location in physical memory.” Excerpts from the Wikipedia Copy-On-Write article having the citation of http://en.wikipedia.org/w/index.php?title=Copy-on-write&oldid=120133246 (last visited Apr. 9, 2007).        
One skilled in the art will understand that a process can be for example, threads-of-execution, a task, a program being executed by a computing element etc.
A number of computer operating systems use copy-on-write technology when spawning a copy of an executing process (for example, in many UNIX variants, the fork( ) system service uses copy-on-write technology to spawn a child process of the parent where the child process-context and the parent process-context share substantial portions of the same physical memory. Thus, a parent process and many child processes can share large amounts of physical memory. Because of the potential savings in physical memory usage, copy-on-write technology is often used with memory-constrained computing devices.
However, there are disadvantages to copy-on-write technology. In particular, if a write operation is attempted by one of the executing processes, physical memory must be allocated for at least the process attempting the write operation. Some copy-on-write embodiments copy the physical memory page to which the write operation is directed. Some copy-on-write embodiments allocate a separate physical memory page for each process-context that shared the copy-on-write page.
In a memory-constrained computing device, the consumption of physical memory resulting from a write attempt to a copy-on-write physical memory page (or a denial of service attack directed to physical memory) can starve a memory-constrained computing device of the memory needed to continue functioning. In this circumstance the device will fail due to the inability to allocate needed memory and the device generally will need to be restarted to recover.
Some embodiments copy-on-write for memory-constrained computing devices can use well-known compression techniques to create a compressed copy of a physical memory page. The physical memory page can then be allocated to another process. However, subsequent memory access to the compressed page requires the system to allocate a memory page within which to decompress the compressed page prior to satisfying the memory access operation. This approach can significantly impact the performance of the device.
For many copy-on-write uses, the content of a shared physical memory page is only minimally modified. Nevertheless, when an attempt is made to modify the shared physical memory page another entire physical memory page is allocated and copied responsive to the copy-on-write operation. Thus, even minor modifications to the content of a shared physical memory page can lead to memory starvation.
It would be advantageous to have some method to enable a memory-constrained computing device to more gracefully recover from low memory situations when multiple physical memory pages have substantially similar content or identical content.